<template>
	<view class="content">
		<view class="bg-white">
			<titleBar title="文章详情" isReturn="true"></titleBar>
		</view>
		<view class="elist" v-for="(item,index) in newList " :key="index" :value="item"
			style=" padding: 5% 0 5% 1%;background: #fff;">
			<view class="titleTop">
				<view class="title">
					<view style="text-decoration:underline">{{item.title}}</view>
				</view>
				<view class="introduce">
					作者：{{item.createName}}
				</view>
				<view class="introduce">
					发布时间：
					{{item.createDate}}
				</view>
				<view class="introduce">
					<text class="uni-lastmsg">文章描述：{{item.remark}}</text>
				</view>
			</view>
			<view class="fenjie"></view>
			<view class="newContent">
				<mp-html :content="item.content" editable=true v-if="item.content!=null"></mp-html>
				<view class="imgContent" v-if="isImgurl">
					<view :class="imgson" v-for="(item,index) in imgList " :key="index" :value="item">
						<image :src="imgList[index]" mode="aspectFill" :class="imgcss">
						</image>
					</view>
				</view>
			</view>
			<view class="fenjie"></view>
			<p style="color: #999;font-size: 14px;text-align: left;width: 30%;display: inline-block;">
				欢迎大家投稿</p>
			<view class="goods" style="text-align: right; display: inline-block;">
				<image :src="goodUrl" mode="" style="width: 20px;height: 20px;"
					@tap="add(item.hits,item.id,item.title)"></image>
				<view class="" style="display: inline-block;margin-right: 5%;">{{item.hits}}</view>
			</view>

		</view>

	</view>
</template>

<script>
	import titleBar from '../../../components/titleBar/titleBar.vue'
	import mpHtml from '../../../components/mp-html/mp-html.vue'
	export default {
		components: {

			titleBar,
			mpHtml

		},
		data() {
			return {
				title: 'detailed',
				isImgurl: true,
				imgcss: '',
				imgson:'',
				newList: [

				],
				imgList: [

				],
				goodNumber: 0,
				goodUrl: '../../../static/img/goodbefore.png',
				ceshi: [

				],
				token: ''
			}
		},
		onLoad: function(option) {
			var that = this
			that.imgList = []
			uni.request({
				url: "https://www.turkeylike.cn:8900/fzulab/article/list",
				method: 'GET',
				success(res) {
					let urlList = res.data.result.list
					console.log(urlList);
					for (var i = 0; i < 1; i++) {
						that.newList.unshift({
							'id': option.id,
							'title': option.title,
							'content': decodeURIComponent(option.content),
							'createName': option.createName,
							'createDate': option.createDate,
							'remark': option.remark,
							'hits': option.hits,
							'titleImgUrl': decodeURIComponent(option.titleImgUrl)
						})
					}

					if (option.titleImgUrl[0] == 'n') {
						that.isImgurl = false
					} else {
						that.isImgurl = true
						that.imgList = that.newList[0].titleImgUrl.split(',')
						if (that.imgList.length < 4) {
							//图片少于3张占满摆放
							that.imgcss = 'one'
							that.imgson='imgson-one'
						} else {
							//图片大于等于4张自适应摆放
							that.imgcss = 'four'
							that.imgson='imgson-two'
						}
					}
					console.log(that.newList);
					console.log(that.imgList);
					console.log(that.imgList.length);
					console.log(option.titleImgUrl[0]);
				}

			})
		},
		methods: {
			add(hits, id, title) {
				this.$data.goodUrl = ''
				this.token = uni.getStorageSync('token')
				if (this.$data.goodNumber == 0) {
					this.$data.goodNumber = 1
					this.$data.goodUrl = '../../../static/img/gooded.png'
					console.log(this.$data.goodNumber);
					hits++
				} else {
					this.$data.goodNumber = 0
					this.$data.goodUrl = '../../../static/img/goodbefore.png'
					console.log(this.$data.goodNumber);
					hits--

				}
				uni.request({
					url: "https://www.turkeylike.cn:8900/fzulab/article/update",
					method: 'POST',
					header: {
						'content-type': 'application/json;charset:utf-8',
						'token': this.token
					},
					data: {
						id: id,
					},
					success(res) {
						console.log(res.data);



					}
				})
				console.log(hits);
				console.log(id);
			}
		}
	}
</script>

<style lang="scss">
	.content {
		height: auto;
		font-size: 40rpx;
		text-align: center;
	}



	.introduce {
		color: lightslategrey;
		text-align: left;
		margin-top: 5px;
		margin-left: 10%;
		font-size: 12px;
	}

	.fenjie {
		width: 90%;
		height: 1px;
		margin: 10px auto 20px auto;
		background: lightgray;

	}

	.newContent {
		text-align: center;
		width: 100%;
		height: auto;
		margin: auto;
	}

	.time-img {
		width: 15px;
		height: 15px;
		margin-right: 5px;
	}

	.uni-lastmsg {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 3; //可设置显示的行数
		line-clamp: 3;
		-webkit-box-orient: vertical;
	}

	.imgContent {
		display: flex;
		width: 100%;
		height: auto;
		flex-direction: row;
		justify-content: left;
		flex-wrap: wrap;
		align-content: left;
	}
	.imgson-one{
		width: 100%;

	}
	.imgson-two{
		width: 50%;

	}
	.imgson-one> .one {
		flex: 1;
		width: 90%;
		height: 150px;
	}

	.imgson-two>.four {
		flex: 1;
		width: 90%;
		height: 150px;
	}

	.goods {
		width: 60%;
	}
</style>
